//
//  UIBarButtonItem+Button.m
//  MyMusic
//
//  Created by sunny on 16/4/2.
//  Copyright © 2016年 sunny. All rights reserved.
//

#import "UIBarButtonItem+Button.h"

@implementation UIBarButtonItem (Button)
+ (UIBarButtonItem *)addButtonWithImage:(UIImage *)image highlightedfImage:(UIImage *)highlightedfImage addTarget:(id)target action:(SEL)sel
{
    UIButton *leftButton = [UIButton buttonWithType:UIButtonTypeCustom];
    [leftButton setImage:image forState:UIControlStateNormal];
    [leftButton setImage:highlightedfImage forState:UIControlStateHighlighted];
    [leftButton sizeToFit];
    //    给按钮添加点击事件
    [leftButton addTarget:target action:sel forControlEvents:UIControlEventTouchUpInside];
    
//    为了解决按钮的点击范围过大
    UIView *view = [[UIView alloc] initWithFrame:leftButton.bounds];
    [view addSubview:leftButton];
    
    return [[UIBarButtonItem alloc] initWithCustomView:view];
    
}
@end
